# -*- coding: utf-8 -*-

import pwd
import spwd

sys_users = {}
usr_no_passwd = []
usr_has_passd = []
users_entry = pwd.getpwall()

for entry in users_entry:
    sys_users[entry.pw_name] = entry.pw_shell

for username in sys_users.keys():
    pass_entry = spwd.getspnam(username)
    if pass_entry.sp_pwd == '!!' or pass_entry.sp_pwd == '*':
        usr_no_passwd.append(pass_entry.sp_nam)
    else:
        usr_has_passd.append(pass_entry.sp_nam)
print("These users have home directory:")
for user, home in sys_users.items():
    if home == '/sbin/nologin':
        continue
    else:
        print("{0:<15}: {1}".format(user, home))
print("")

print("These users can login system:")
for user in usr_has_passd:
    print(user)
